package com.axjy.service.impl;

import com.axjy.dao.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> search(Integer userRole) {
        List<User> list=userMapper.search(userRole);
        return list;
    }

    @Override
    public User login(String userCode, String userPassword) {
        User user=userMapper.find(userCode,userPassword);
        return user;
    }

    @Override
    public void updateCard(Integer id, String cardPic, String cardDesc) {
        User u= new User();
        u.setId(id);
        u.setCardDesc(cardDesc);
        u.setCardPic(cardPic);
        userMapper.updateCard(u);
    }

    @Override
    public String checkCode(String userCode) {
       Integer count=userMapper.checkCode(userCode);
       if(count>0){
           return "账号已存在~";
       }
       return "该用户账号可以使用！";
    }

    @Override
    public User get(Integer id) {
        return userMapper.get(id);
    }

    @Override
    public void add(User u, HttpSession session) {
        userMapper.add(u);
    }
}
